package com.zsl.blog.api.handler;

import com.zsl.blog.api.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//ControllerAdvice注解对加了controller的方法进行AOP拦截
//@ControllerAdvice
public class GlobalExceptionHandler {
    //ExceptionHandler注解用于处理Exception.class的异常
    @ExceptionHandler(Exception.class)
    //ResponseBody注解返回json数据,不返回页面
    @ResponseBody
    public Result doException(Exception e){
        e.printStackTrace();
        return Result.fail(-9999,e.getMessage());
    }
}
